/*     */ package com.cr.web.controller.system;
/*     */ 
/*     */ import com.cr.common.annotation.Log;
/*     */ import com.cr.common.core.controller.BaseController;
/*     */ import com.cr.common.core.domain.AjaxResult;
/*     */ import com.cr.common.core.domain.Ztree;
/*     */ import com.cr.common.core.domain.entity.SysDept;
/*     */ import com.cr.common.core.domain.entity.SysRole;
/*     */ import com.cr.common.enums.BusinessType;
/*     */ import com.cr.common.utils.MyStringUtils;
import org.apache.commons.lang3.StringUtils;
/*     */ import com.cr.system.service.ISysDeptService;
/*     */ import java.util.List;
/*     */ import org.apache.shiro.authz.annotation.RequiresPermissions;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.ModelMap;
/*     */ import org.springframework.validation.annotation.Validated;
/*     */ import org.springframework.web.bind.annotation.GetMapping;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.PostMapping;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/system/dept"})
/*     */ public class SysDeptController extends BaseController {
/*  34 */   private String prefix = "system/dept";
/*     */   
/*     */   @Autowired
/*     */   private ISysDeptService deptService;
/*     */   
/*     */   @RequiresPermissions({"system:dept:view"})
/*     */   @GetMapping
/*     */   public String dept() {
/*  43 */     return this.prefix + "/dept";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:dept:list"})
/*     */   @PostMapping({"/list"})
/*     */   @ResponseBody
/*     */   public List<SysDept> list(SysDept dept) {
/*  51 */     List<SysDept> deptList = this.deptService.selectDeptList(dept);
/*  52 */     return deptList;
/*     */   }
/*     */   
/*     */   @GetMapping({"/add/{parentId}"})
/*     */   public String add(@PathVariable("parentId") Long parentId, ModelMap mmap) {
/*  61 */     if (!getSysUser().isAdmin())
/*  63 */       parentId = getSysUser().getDeptId(); 
/*  65 */     mmap.put("dept", this.deptService.selectDeptById(parentId));
/*  66 */     return this.prefix + "/add";
/*     */   }
/*     */   
/*     */   @Log(title = "部门管理", businessType = BusinessType.INSERT)
/*     */   @RequiresPermissions({"system:dept:add"})
/*     */   @PostMapping({"/add"})
/*     */   @ResponseBody
/*     */   public AjaxResult addSave(@Validated SysDept dept) {
/*  78 */     if ("1".equals(this.deptService.checkDeptNameUnique(dept)))
/*  80 */       return error("新增部门'" + dept.getDeptName() + "'失败，部门名称已存在"); 
/*  82 */     dept.setCreateBy(getLoginName());
/*  83 */     return toAjax(this.deptService.insertDept(dept));
/*     */   }
/*     */   
/*     */   @GetMapping({"/edit/{deptId}"})
/*     */   public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap) {
/*  92 */     this.deptService.checkDeptDataScope(deptId);
/*  93 */     SysDept dept = this.deptService.selectDeptById(deptId);
/*  94 */     if (MyStringUtils.isNotNull(dept) && 100L == deptId.longValue())
/*  96 */       dept.setParentName("无"); 
/*  98 */     mmap.put("dept", dept);
/*  99 */     return this.prefix + "/edit";
/*     */   }
/*     */   
/*     */   @Log(title = "部门管理", businessType = BusinessType.UPDATE)
/*     */   @RequiresPermissions({"system:dept:edit"})
/*     */   @PostMapping({"/edit"})
/*     */   @ResponseBody
/*     */   public AjaxResult editSave(@Validated SysDept dept) {
/* 111 */     if ("1".equals(this.deptService.checkDeptNameUnique(dept)))
/* 113 */       return error("修改部门'" + dept.getDeptName() + "'失败，部门名称已存在"); 
/* 115 */     if (dept.getParentId().equals(dept.getDeptId()))
/* 117 */       return error("修改部门'" + dept.getDeptName() + "'失败，上级部门不能是自己"); 
/* 119 */     if (StringUtils.equals("1", dept.getStatus()) && this.deptService
/* 120 */       .selectNormalChildrenDeptById(dept.getDeptId()) > 0)
/* 122 */       return AjaxResult.error("该部门包含未停用的子部门！"); 
/* 124 */     dept.setUpdateBy(getLoginName());
/* 125 */     return toAjax(this.deptService.updateDept(dept));
/*     */   }
/*     */   
/*     */   @Log(title = "部门管理", businessType = BusinessType.DELETE)
/*     */   @RequiresPermissions({"system:dept:remove"})
/*     */   @GetMapping({"/remove/{deptId}"})
/*     */   @ResponseBody
/*     */   public AjaxResult remove(@PathVariable("deptId") Long deptId) {
/* 137 */     if (this.deptService.selectDeptCount(deptId) > 0)
/* 139 */       return AjaxResult.warn("存在下级部门,不允许删除"); 
/* 141 */     if (this.deptService.checkDeptExistUser(deptId))
/* 143 */       return AjaxResult.warn("部门存在用户,不允许删除"); 
/* 145 */     return toAjax(this.deptService.deleteDeptById(deptId));
/*     */   }
/*     */   
/*     */   @PostMapping({"/checkDeptNameUnique"})
/*     */   @ResponseBody
/*     */   public String checkDeptNameUnique(SysDept dept) {
/* 155 */     return this.deptService.checkDeptNameUnique(dept);
/*     */   }
/*     */   
/*     */   @GetMapping({"/selectDeptTree/{deptId}", "/selectDeptTree/{deptId}/{excludeId}"})
/*     */   public String selectDeptTree(@PathVariable("deptId") Long deptId, @PathVariable(value = "excludeId", required = false) String excludeId, ModelMap mmap) {
/* 168 */     mmap.put("dept", this.deptService.selectDeptById(deptId));
/* 169 */     mmap.put("excludeId", excludeId);
/* 170 */     return this.prefix + "/tree";
/*     */   }
/*     */   
/*     */   @GetMapping({"/treeData"})
/*     */   @ResponseBody
/*     */   public List<Ztree> treeData() {
/* 180 */     List<Ztree> ztrees = this.deptService.selectDeptTree(new SysDept());
/* 181 */     return ztrees;
/*     */   }
/*     */   
/*     */   @GetMapping({"/treeData/{excludeId}"})
/*     */   @ResponseBody
/*     */   public List<Ztree> treeDataExcludeChild(@PathVariable(value = "excludeId", required = false) Long excludeId) {
/* 191 */     SysDept dept = new SysDept();
/* 192 */     dept.setExcludeId(excludeId);
/* 193 */     List<Ztree> ztrees = this.deptService.selectDeptTreeExcludeChild(dept);
/* 194 */     return ztrees;
/*     */   }
/*     */   
/*     */   @GetMapping({"/roleDeptTreeData"})
/*     */   @ResponseBody
/*     */   public List<Ztree> deptTreeData(SysRole role) {
/* 204 */     List<Ztree> ztrees = this.deptService.roleDeptTreeData(role);
/* 205 */     return ztrees;
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\classes\com.zip!\com\cr\web\controller\system\SysDeptController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */